﻿#include "stdafx.h"
#include "def_spell.h"
#include <map>
#include <vector>
#include "GameInfo.h"
#include "Team_Raid_Info.h"

struct HealConfig
{
	SpellID spell_id;
	int		heal_freq;
	int		heal_value;
};
using VecHealConfig = std::vector<HealConfig>;
using MapHealConfig = std::map<SpellID, HealConfig>;
MapHealConfig map_heal_config_;
VecHealConfig vec_heal_config_ = {
	{Rejuvenation, 18, 879},
	{Regrowth, 27, 1763},
	{Lifebloom, 8, 987},
	{Grove_Tending, 27, 3106},
	{Wild_Growth, 9,  969},
	{Cenarion_Ward, 18,5388},
};

int GetHealExceptHpTotal(SpellID spell_id, int duration)
{
	auto it = map_heal_config_.find(spell_id);
	if (it != map_heal_config_.end())
	{
		auto& config = it->second;
		int value = static_cast<int>(config.heal_value*(duration*1.0f / config.heal_freq));
		return value;
	}
	return 0;
}

void InitHealSpellConfigConfig()
{
	map_heal_config_.clear();
	for (HealConfig& config : vec_heal_config_)
	{
		map_heal_config_[config.spell_id] = config;
	}
}


using VecSpellCostMana = std::vector<SpellCostMana>;
using MapSpellCostMana = std::map<SpellID, SpellCostMana>;

VecSpellCostMana vec_spell_cost_mana_ = {
	{Rejuvenation, 2100},
	{Regrowth, 2800, 0},
	{Lifebloom, 2240},
	{Swiftmend, 2800},
	{Wild_Growth, 5600},
	{Cenarion_Ward, 1840},
	{Rebirth, 1},
	{Ironbark, 1},
	{Revive, 800},
	{Incarnation_Chosen_of_Elune, 1},
	{Starsurge, 40, 8},
	{Starfall, 50, 8},
	{Sunfire, 1, 8},
	{Moonfire, 1, 8},
	{Lunar_Strike, 1, 8},
	{Solar_Wrath, 0, 8},
	{Solar_Wrath_Balance, 1, 8},
	{Celestial_Alignment, 1, 8},
	{Moonkin_Form, 1, 8},
	{Memory_of_Lucid_Dreams, 1, 8},
	{Concentrated_Flame, 1, 8},
	{Reaping_Flames, 1, 8},
};


MapSpellCostMana map_spell_cost_mana_;

SpellCostMana GetSpellCostMana(SpellID spell_id)
{
	auto it = map_spell_cost_mana_.find(spell_id);
	if (it != map_spell_cost_mana_.end())
	{
		return it->second;
	}
	return { SpellID_None, 0 , -1 };
}

void InitSpellCostManaConfig()
{
	map_spell_cost_mana_.clear();
	for (SpellCostMana& config : vec_spell_cost_mana_)
	{
		map_spell_cost_mana_[config.spell_id] = config;
	}
}

// RESOURCE_ASTRAL_POWER
struct SpelAddAstralPower
{
	SpellID spell_id = SpellID_None;
	int		add_astral_power = 0;
};

using VecSpellAddAstralPower = std::vector<SpelAddAstralPower>;
using MapSpellAddAstralPower = std::map<SpellID, SpelAddAstralPower>;

VecSpellAddAstralPower vec_spell_add_astral_power = {
	{Solar_Wrath_Balance, 8},
	{Sunfire, 3},
	{Moonfire, 3},
	{Lunar_Strike, 12},
};

MapSpellAddAstralPower map_spell_add_astral_power;

void InitSpellAddAstralPowerConfig()
{
	map_spell_add_astral_power.clear();
	for (auto& config : vec_spell_add_astral_power)
	{
		map_spell_add_astral_power[config.spell_id] = config;
	}
}

int GetSpellAp(SpellID spell_id)
{
	auto it = map_spell_add_astral_power.find(spell_id);
	if (it != map_spell_add_astral_power.end())
	{
		return it->second.add_astral_power;
	}
	else
	{
		ASSERT(false);
	}
	return 0;
}

struct SpellFreeBuff {
	SpellID spell_id;
	SpellID spell_id_free;
};
using MapSpellFreeBuff = std::map<SpellID, SpellID>;

MapSpellFreeBuff map_spell_free_buff_ = {
	{Regrowth, Clearcasting},
};
SpellID GetSpellFreeBuff(SpellID spell_id)
{
	if (GameInfo::inst().GetPlayer().buff(Innervate).Up())
	{
		return Innervate;
	}
	auto it = map_spell_free_buff_.find(spell_id);
	if (it != map_spell_free_buff_.end())
	{
		return it->second;
	}
	return SpellID_None;
}